package com.wuxf.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;
import com.wuxf.entity.CarArea;
import com.wuxf.entity.CarCompany;
import com.wuxf.entity.ConsumeInfo;
import com.wuxf.entity.DicDataInfo;
import com.wuxf.entity.ExcelData;
import com.wuxf.entity.ResponseBodyEntity;
import com.wuxf.entity.custom.ConsumeCustom;
import com.wuxf.entity.custom.UserInfoCustom;
import com.wuxf.service.CarAreaService;
import com.wuxf.service.CarCompanyService;
import com.wuxf.service.ConsumeService;
import com.wuxf.service.DicDataService;
import com.wuxf.util.DateUtils;
import com.wuxf.util.ExcelUtils;

@Controller
@SuppressWarnings({ "rawtypes", "unchecked" })
public class DataAnalyzeController {

	@Autowired
	private DicDataService dicDataService;
	@Autowired
	private ConsumeService consumeService;
	@Autowired
	private CarAreaService carAreaService;
	@Autowired
	private CarCompanyService carCompanyService;
	
	@RequestMapping("dataAnalyze/goToindex")
	public String goToindex(Model model) {
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("typeDicDataArr",typeDicDatas);
		return "dataAnalyze/index";
	}
	

	@RequestMapping("dataAnalyze/goToQueryByCarNo")
	public String goToQueryByCarNo(Model model) {
		return "dataAnalyze/queryByCarNo";
	}
	@RequestMapping("dataAnalyze/queryByCarNo")
	public @ResponseBody ResponseBodyEntity queryByCarNo(int page,int limit,String carno,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("carNo", carno);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		PageInfo<List<ConsumeCustom>> consumeCustoms = consumeService.findByPageGroupCarno(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms.getList());
		responseBodyEntity.setCount(consumeCustoms.getTotal());
		return responseBodyEntity;
	}
	
	@RequestMapping("dataAnalyze/goToCarCompanyManage")
	public String goToCarCompanyManage(Model model) {
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		model.addAttribute("unitDicDataArr", unitDicDatas);
		return "dataAnalyze/CarCompanyManage";
	}
	@RequestMapping("dataAnalyze/saveCarCompany")
	public @ResponseBody ResponseBodyEntity saveCarCompany(HttpSession session,CarCompany carCompany){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		UserInfoCustom userInfoCustom = null;
		if(session.getAttribute("userInfoCustom") != null) {
			userInfoCustom = (UserInfoCustom)session.getAttribute("userInfoCustom");
		}
		carCompany.setCreateUser(userInfoCustom.getUserId());
		carCompany.setUpdateTime(DateUtils.getNowDate());
		carCompanyService.saveCarCompany(carCompany);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setState("1");
		return responseBodyEntity;
	}
	@RequestMapping("dataAnalyze/deleteCarCompany")
	public @ResponseBody ResponseBodyEntity deleteCarCompany(int carCompanyId){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		carCompanyService.deleteCarCompany(carCompanyId);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setState("1");
		return responseBodyEntity;
	}
	
	//校验车牌在这个区域是否已经录入
	@RequestMapping("/dataAnalyze/checkCarNoAndArea")
	public @ResponseBody ResponseBodyEntity checkCarNoAndArea(int areaId,String carno){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		HashMap paraMap = new HashMap();
		paraMap.put("areaId", areaId);
		paraMap.put("carno", carno);
		int counts = carAreaService.checkCarNoAndArea(paraMap);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setState("1");
		responseBodyEntity.setCount(counts);
		return responseBodyEntity;
	}
	//校验车牌在这个单位是否已经录入
		@RequestMapping("/dataAnalyze/checkCarNoAndCompany")
		public @ResponseBody ResponseBodyEntity checkCarNoAndCompany(String company,String carno){
			ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
			HashMap paraMap = new HashMap();
			paraMap.put("company", company);
			paraMap.put("carno", carno);
			int counts = carCompanyService.checkCarNoAndCompany(paraMap);
			responseBodyEntity.setCode(0);
			responseBodyEntity.setState("1");
			responseBodyEntity.setCount(counts);
			return responseBodyEntity;
		}
	
	@RequestMapping("dataAnalyze/findCarCompanyByMapAndPage")
	public @ResponseBody ResponseBodyEntity findCarCompanyByMapAndPage(HttpSession session,int page,int limit,String pwdValue,String ticketType,String generateDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		PageInfo<List<CarCompany>> carCompanys = carCompanyService.findByMapAndPage(new HashMap(), pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(carCompanys.getList());
		responseBodyEntity.setCount(carCompanys.getTotal());
		return responseBodyEntity;
	}
	
	@RequestMapping("dataAnalyze/goToCarAreaManage")
	public String goToCarAreaManage(Model model) {
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		model.addAttribute("areaDicDataArr", areaDicDatas);
		HashMap paraMap = new HashMap();
		List<CarArea> carAreas = carAreaService.findByMap(paraMap);
		model.addAttribute("carAreas", carAreas);
		return "dataAnalyze/CarAreaManage";
	}
	@RequestMapping("dataAnalyze/saveCarArea")
	public @ResponseBody ResponseBodyEntity saveCarArea(HttpSession session,CarArea carArea){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		UserInfoCustom userInfoCustom = null;
		if(session.getAttribute("userInfoCustom") != null) {
			userInfoCustom = (UserInfoCustom)session.getAttribute("userInfoCustom");
		}
		carArea.setCreateUser(userInfoCustom.getUserId());
		carArea.setUpdateTime(DateUtils.getNowDate());
		carAreaService.saveCarArea(carArea);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setState("1");
		return responseBodyEntity;
	}
	@RequestMapping("dataAnalyze/deleteCarArea")
	public @ResponseBody ResponseBodyEntity deleteCarArea(int carAreaId){
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		carAreaService.deleteCarArea(carAreaId);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setState("1");
		return responseBodyEntity;
	}
	
	@RequestMapping("dataAnalyze/findCarAreaByMapAndPage")
	public @ResponseBody ResponseBodyEntity findByMapAndPage(HttpSession session,int page,int limit,String pwdValue,String ticketType,String generateDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		PageInfo<List<CarArea>> carAreas = carAreaService.findByMapAndPage(new HashMap(), pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(carAreas.getList());
		responseBodyEntity.setCount(carAreas.getTotal());
		return responseBodyEntity;
	}
	
	
	@RequestMapping("dataAnalyze/goToQueryBySynthesis")
	public String goToQueryBySynthesis(Model model) {
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		model.addAttribute("typeDicDataArr", typeDicDatas);
		model.addAttribute("areaDicDataArr", areaDicDatas);
		model.addAttribute("unitDicDataArr", unitDicDatas);
		return "dataAnalyze/queryBySynthesis";
	}
	
	/**
	 * 综合查询页面
	 * @return
	 */
	@RequestMapping("dataAnalyze/queryBySynthesis")
	public @ResponseBody ResponseBodyEntity queryBySynthesis(int page,int limit,String areaId,String ticketType,String unit,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("areaId", areaId);
		paraMap.put("unit", unit);
		paraMap.put("ticketType", ticketType);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		PageInfo<List<ConsumeCustom>> consumeCustoms = consumeService.findByPageGroupSynthesis(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms.getList());
		responseBodyEntity.setCount(consumeCustoms.getTotal());
		return responseBodyEntity;
	}
	
	@RequestMapping("dataAnalyze/goToQueryByArea")
	public String goToQueryByArea(Model model) {
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		model.addAttribute("areaDicDataArr", areaDicDatas);
		return "dataAnalyze/queryByArea";
	}
	/**
	 * 区域查询页面
	 * @return
	 */
	@RequestMapping("dataAnalyze/findByArea")
	public @ResponseBody ResponseBodyEntity findByArea(int page,int limit,String areaId,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("areaId", areaId);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		PageInfo<List<ConsumeCustom>> consumeCustoms = consumeService.findByPageGroupArea(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms.getList());
		responseBodyEntity.setCount(consumeCustoms.getTotal());
		return responseBodyEntity;
	}
	
	
	
	@RequestMapping("dataAnalyze/goToQueryByType")
	public String goToQueryByType(Model model) {
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("typeDicDataArr",typeDicDatas);
		return "dataAnalyze/queryByType";
	}
	
	/**
	 * 类型查询页面
	 * @return
	 */
	@RequestMapping("dataAnalyze/findByType")
	public @ResponseBody ResponseBodyEntity findByType(int page,int limit,String ticketType,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("ticketType", ticketType);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		List<ConsumeCustom> consumeCustoms = consumeService.findByPageGroupType(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms);
		responseBodyEntity.setCount(consumeCustoms.size());
		return responseBodyEntity;
	}
	
	
	@RequestMapping("dataAnalyze/goToQueryByUnit")
	public String goToQueryByUnit(Model model) {
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		model.addAttribute("unitDicDataArr", unitDicDatas);
		return "dataAnalyze/queryByUnit";
	}
	
	/**
	 * 单位查询页面
	 * @return
	 */
	@RequestMapping("dataAnalyze/findByUnit")
	public @ResponseBody ResponseBodyEntity findByUnit(int page,int limit,String unit,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("unit", unit);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		PageInfo<List<ConsumeCustom>> consumeCustoms = consumeService.findByPageGroupUnit(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms.getList());
		responseBodyEntity.setCount(consumeCustoms.getTotal());
		return responseBodyEntity;
	}
	
	/**
	 * 跳转到详情页面
	 * @param model
	 * @param areaId
	 * @param ticketType
	 * @param unit
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("dataAnalyze/goToDetails")
	public String goToDetailsByArea(Model model, String areaId,String carNo, String ticketType, String unit, String startDate, String endDate) {
		model.addAttribute("areaId", areaId);
		model.addAttribute("carNo", carNo);
		model.addAttribute("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		model.addAttribute("endDate", endDate);
		model.addAttribute("ticketType", ticketType);
		model.addAttribute("unit", unit);
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		return "dataAnalyze/details";
	}
	
	/**
	 * 根据条件查询消费详情
	 * @param model
	 * @param areaId
	 * @param ticketType
	 * @param unit
	 * @param startDate
	 * @param endDate
	 * @return
	 */
	@RequestMapping("dataAnalyze/findByDetails")
	public @ResponseBody ResponseBodyEntity findByDetails(int page,int limit,Model model, String carNo,String areaId, String ticketType, String unit, String startDate, String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		PageInfo pageInfo = new PageInfo();
		pageInfo.setPageNum(page);
		pageInfo.setPageSize(limit);
		HashMap paraMap = new HashMap();
		paraMap.put("areaId", areaId);
		paraMap.put("carNo", carNo);
		paraMap.put("ticketType", ticketType);
		paraMap.put("unit", unit);
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
  			endDate = endDate+"3";
  		}
		paraMap.put("endDate", endDate);
		PageInfo<List<ConsumeCustom>> consumeCustoms = consumeService.findByMapAndPage(paraMap,pageInfo);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms.getList());
		responseBodyEntity.setCount(consumeCustoms.getTotal());
		return responseBodyEntity;
	}
	
	
	
	
	
	@RequestMapping("dataAnalyze/goToStatistics")
	public String goToStatistics(Model model) {
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		return "dataAnalyze/statistics";
	}
	
	@RequestMapping("dataAnalyze/goToQuery")
	public String goToQuery(Model model) {
		List<DicDataInfo> typeDicDatas = dicDataService.findByEnumTypeId("1");
		List<DicDataInfo> areaDicDatas = dicDataService.findByEnumTypeId("2");
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		
		model.addAttribute("typeDicDatas", JSONArray.toJSONString(typeDicDatas));
		model.addAttribute("areaDicDatas", JSONArray.toJSONString(areaDicDatas));
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		return "dataAnalyze/query";
	}
	
	@RequestMapping("dataAnalyze/goToDetails/{unit}")
	public String goToDetails(@PathVariable String unit,Model model) {
		model.addAttribute("unit", unit);
		List<DicDataInfo> unitDicDatas = dicDataService.findByEnumTypeId("4");
		
		model.addAttribute("unitDicDatas", JSONArray.toJSONString(unitDicDatas));
		return "dataAnalyze/details";
	}
	
	
	/**
	 * 展示页面
	 * @return
	 */
	@RequestMapping("dataAnalyze/findTotal")
	public @ResponseBody ResponseBodyEntity findTotal() {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		HashMap paraMap = new HashMap();
		List<ConsumeInfo> consumeInfos = consumeService.findTotal(paraMap);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeInfos);
		responseBodyEntity.setCount(consumeInfos.size());
		return responseBodyEntity;
	}
	
	/**
	 * 查询页面
	 * @return
	 
	@RequestMapping("dataAnalyze/findByMap")
	public @ResponseBody ResponseBodyEntity findByMap(String unit,String startDate,String endDate) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		HashMap paraMap = new HashMap();
		paraMap.put("unit", unit);
		if(StringUtils.isNotBlank(startDate)) {
			startDate = startDate.replaceAll("-", "");
		}
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
			endDate = endDate.replaceAll("-", "")+"3";
		}
		paraMap.put("endDate", endDate);
		List<ConsumeCustom> consumeCustoms = consumeService.findByGroup(paraMap);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms);
		responseBodyEntity.setCount(consumeCustoms.size());
		return responseBodyEntity;
	}*/
	
	/**
	 * 查询详情页面
	 * @return
	
	@RequestMapping("dataAnalyze/findByDetails")
	public @ResponseBody ResponseBodyEntity findByDetails(String unit,String startDate,String endDate,String licenseNum) {
		ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
		HashMap paraMap = new HashMap();
		paraMap.put("licenseNum", licenseNum);
		paraMap.put("unit", unit);
		if(StringUtils.isNotBlank(startDate)) {
			startDate = startDate.replaceAll("-", "");
		}
		paraMap.put("startDate", startDate);
		if(StringUtils.isNotBlank(endDate)) {
			endDate = endDate.replaceAll("-", "")+"3";
		}
		paraMap.put("endDate", endDate);
		List<ConsumeCustom> consumeCustoms = consumeService.findByMap(paraMap);
		responseBodyEntity.setCode(0);
		responseBodyEntity.setData(consumeCustoms);
		responseBodyEntity.setCount(consumeCustoms.size());
		return responseBodyEntity;
	}
	 */
	@RequestMapping(value = "/exportByUnit", method = RequestMethod.GET)  
    public void exportByUnit(HttpServletResponse response,String unit,String startDate,String endDate) throws Exception {  
        ExcelData data = new ExcelData();  
        data.setName("导出详文件");  
        List<String> titles = new ArrayList();  
        titles.add("单位");  
        titles.add("车次");  
        titles.add("重量");
        data.setTitles(titles);  

        List<List<Object>> rows = new ArrayList();  
        HashMap paraMap = new HashMap();
	  		paraMap.put("unit", unit);
	  		paraMap.put("startDate", startDate);
	  		if(StringUtils.isNotBlank(endDate)) {
	  			endDate = endDate+"3";
	  		}
	  		paraMap.put("endDate", endDate);
	  		List<ConsumeCustom> consumeCustoms = consumeService.findByMapGroupUnit(paraMap);
	  		for (ConsumeCustom consumeCustom : consumeCustoms) {
	  			List<Object> objects = new ArrayList<Object>();
	  			objects.add(dicDataService.findByEnumTypeId("4",consumeCustom.getDicDataValue()).get(0).getDicDataName());  
	  			objects.add(consumeCustom.getCarTims());  
	  			objects.add(consumeCustom.getWeights());
	  			rows.add(objects);
			}
        data.setRows(rows);
        //生成本地  
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  
        String fileName=fdate.format(new Date())+".xls";  
        ExcelUtils.exportExcel(response,fileName,data);  
    }
	
	@RequestMapping(value = "/exportByType", method = RequestMethod.GET)  
    public void exportByType(HttpServletResponse response,String ticketType,String startDate,String endDate) throws Exception {  
        ExcelData data = new ExcelData();  
        data.setName("导出详文件");  
        List<String> titles = new ArrayList();  
        titles.add("发票类型");  
        titles.add("车次");  
        titles.add("重量");
        data.setTitles(titles);  

        List<List<Object>> rows = new ArrayList();  
        HashMap paraMap = new HashMap();
	  		paraMap.put("ticketType", ticketType);
	  		paraMap.put("startDate", startDate);
	  		if(StringUtils.isNotBlank(endDate)) {
	  			endDate = endDate+"3";
	  		}
	  		paraMap.put("endDate", endDate);
	  		List<ConsumeCustom> consumeCustoms = consumeService.findByMapGroupType(paraMap);
	  		for (ConsumeCustom consumeCustom : consumeCustoms) {
	  			List<Object> objects = new ArrayList<Object>();
	  			objects.add(dicDataService.findByEnumTypeId("1",consumeCustom.getDicDataValue()).get(0).getDicDataName());  
	  			objects.add(consumeCustom.getCarTims());  
	  			objects.add(consumeCustom.getWeights());
	  			rows.add(objects);
			}
        data.setRows(rows);
        //生成本地  
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  
        String fileName=fdate.format(new Date())+".xls";  
        ExcelUtils.exportExcel(response,fileName,data);  
    }
	
	@RequestMapping(value = "/exportByAreaId", method = RequestMethod.GET)  
    public void exportByAreaId(HttpServletResponse response,String areaId,String startDate,String endDate) throws Exception {  
        ExcelData data = new ExcelData();  
        data.setName("导出详文件");  
        List<String> titles = new ArrayList();  
        titles.add("区域");  
        titles.add("车次");  
        titles.add("重量");
        data.setTitles(titles);  

        List<List<Object>> rows = new ArrayList();  
        HashMap paraMap = new HashMap();
	  		paraMap.put("areaId", areaId);
	  		paraMap.put("startDate", startDate);
	  		if(StringUtils.isNotBlank(endDate)) {
	  			endDate = endDate+"3";
	  		}
	  		paraMap.put("endDate", endDate);
	  		List<ConsumeCustom> consumeCustoms = consumeService.findByMapGroupArea(paraMap);
	  		for (ConsumeCustom consumeCustom : consumeCustoms) {
	  			List<Object> objects = new ArrayList<Object>();
	  			objects.add(dicDataService.findByEnumTypeId("2",consumeCustom.getDicDataValue()).get(0).getDicDataName());  
	  			objects.add(consumeCustom.getCarTims());  
	  			objects.add(consumeCustom.getWeights());
	  			rows.add(objects);
			}
        data.setRows(rows);
        //生成本地  
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  
        String fileName=fdate.format(new Date())+".xls";  
        ExcelUtils.exportExcel(response,fileName,data);  
    }
	
	@RequestMapping(value = "/exportBySynthesis", method = RequestMethod.GET)  
    public void exportBySynthesis(HttpServletResponse response,String areaId,String ticketType,String unit,String startDate,String endDate) throws Exception {  
        ExcelData data = new ExcelData();  
        data.setName("导出详文件");  
        List<String> titles = new ArrayList();  
        titles.add("单位");  
        titles.add("区域");  
        titles.add("类型");  
        titles.add("车次");  
        titles.add("重量");
        data.setTitles(titles);  

        List<List<Object>> rows = new ArrayList();  
        HashMap paraMap = new HashMap();
	  		paraMap.put("areaId", areaId);
			paraMap.put("unit", unit);
			paraMap.put("ticketType", ticketType);
	  		paraMap.put("startDate", startDate);
	  		if(StringUtils.isNotBlank(endDate)) {
	  			endDate = endDate+"3";
	  		}
	  		paraMap.put("endDate", endDate);
	  		List<ConsumeCustom> consumeCustoms = consumeService.findByGroupSynthesis(paraMap);
	  		for (ConsumeCustom consumeCustom : consumeCustoms) {
	  			List<Object> objects = new ArrayList<Object>();
	  			objects.add(dicDataService.findByEnumTypeId("4",consumeCustom.getUnit()).get(0).getDicDataName());
	  			objects.add(dicDataService.findByEnumTypeId("2",consumeCustom.getAreaId()+"").get(0).getDicDataName());
	  			objects.add(dicDataService.findByEnumTypeId("1",consumeCustom.getTicketType()).get(0).getDicDataName());
	  			objects.add(consumeCustom.getCarTims());  
	  			objects.add(consumeCustom.getWeights());
	  			rows.add(objects);
			}
        data.setRows(rows);
        //生成本地  
        SimpleDateFormat fdate=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");  
        String fileName=fdate.format(new Date())+".xls";  
        ExcelUtils.exportExcel(response,fileName,data);  
    }
	
	
}
